import cv2
import numpy as np

def padding1(img_path,K_size):
    img=cv2.imread(img_path)
    [H,W,C]=img.shape
    R=K_size//2
    padding=np.zeros((H+2*R,W+2*R,C),dtype=np.uint8)
    padding[R:R+H,R:R+W,:]=img.copy().astype(np.uint8)
    return padding

def padding2(img_path,K_size):
    img=cv2.imread(img_path)
    [H,W,C]=img.shape
    R=K_size//2
    padding=np.zeros((H+2*R,W+2*R,C),dtype=np.uint8)
    padding[R:R+H,R:R+W,:]=img.copy().astype(np.uint8)
    padding[0:R,0:R,:]=img[0,0,:]
    padding[0:R,R+W:2*R+W,:]=img[0,W-1,:]
    padding[H+R:H+2*R,0:R,:]=img[H-1,0,:]
    padding[H+R:H+2*R,R+W:2*R+W,:]=img[H-1,W-1,:]
    for i in range(R):
        padding[i,R:R+W,:]=img[0,:,:]
        padding[R+H+i,R:R+W,:]=img[-1,:,:]
        padding[R:R+H,i,:]=img[:,0,:]
        padding[R:R+H,R+W+i,:]=img[:,-1,:] 
    return padding

if __name__ == "__main__":
    img='YOIMIYA.jpg'
    p1=padding1(img,21)
    p2=padding2(img,21)
    compare = np.hstack([p1 , p2 ])
    cv2.namedWindow('compare',cv2.WINDOW_NORMAL)
    cv2.imshow('compare',compare)
    cv2.waitKey(0)
    